<template>
  <el-container class="main_con" >
       <ufrom @submit="saveData" ref="ufrom">

        <el-form size="medium" label-width="140px" :model="obj.configuration" :rules="formRules">
          <div class="setting_body_item">
            <div class="header">余额转赠</div>
            <div class="conetnt edit_con">
              <div class="edit_content">
                <el-form-item label="是否开启">
                  <el-radio-group v-model="obj.configuration.balance.open">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>

                </el-form-item>
                <el-form-item label="单次最低转赠金额" prop="balance.min"><el-input style="width:360px;" v-model="obj.configuration.balance.min"></el-input></el-form-item>
                <el-form-item label="手续费">
                  <el-radio-group v-model="obj.configuration.balance.charge_status">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                  <div style="color: #909399; font-size: 12px">设置"转赠手续费"后，转赠金额将扣除手续费后转赠给受赠用户</div>

                </el-form-item>
                <el-form-item prop="balance.charge" label="手续费%"
                v-if="obj.configuration.balance.charge_status == 1" >
                  <el-input style="width:360px;" v-model="obj.configuration.balance.charge"></el-input>
                </el-form-item>
                <el-form-item label="手续费名称" v-if="obj.configuration.balance.charge_status == 1"
               >
                  <el-input v-model="obj.configuration.balance.charge_name" style="width:360px;" maxlength="6" show-word-limit></el-input>
                </el-form-item>
                <el-form-item label="活动规则">
                  <tinymce  v-model="obj.configuration.balance.remark" :height="400" />

                </el-form-item>
              </div>
            </div>
          </div>

          <div class="setting_body_item">
            <div class="header">积分转赠</div>
            <div class="conetnt edit_con">
              <div class="edit_content">
                <el-form-item label="是否开启">
                  <el-radio-group v-model="obj.configuration.integral.open">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="单次最低转赠金额" prop="integral.min"><el-input style="width:360px;" v-model.number="obj.configuration.integral.min"></el-input></el-form-item>
                <el-form-item label="手续费">
                  <el-radio-group v-model="obj.configuration.integral.charge_status">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                  <div style="color: #909399; font-size: 12px">设置“转赠手续费”后，转赠积分将扣除手续费后转赠给受赠用户，小数点部分将进行取整</div>
                </el-form-item>
                <el-form-item label="手续费%" prop="integral.charge"><el-input style="width:360px;" v-model.number="obj.configuration.integral.charge"></el-input></el-form-item>
                <el-form-item label="手续费名称">
                  <el-input v-model="obj.configuration.integral.charge_name" style="width:360px;" maxlength="6" show-word-limit></el-input>
                </el-form-item>
                <el-form-item label="活动规则">
                  <tinymce  v-model="obj.configuration.integral.remark" :height="400" />

                </el-form-item>
              </div>
            </div>
          </div>
        </el-form>
       </ufrom>
  </el-container>
</template>

<script>
import {addSiteConfig, editSiteConfig, getSiteConfig} from '@/api/mall/setting';
import Tinymce from '@/components/Tinymce';

export default {
  data() {
    return {
      isLoading: false,
      obj: {
        type: 'assettransfer',
        status: 1,
        configuration: {
          balance: {
            min: 0,
            open: 0,
            charge: 0,
            remark: '',
            search: '',
            charge_name: '',
            charge_status: 0
          },
          integral: {
            min: 0,
            open: 0,
            charge: 0,
            remark: '',
            search: '',
            charge_name: '',
            charge_status: 0
          }
        }
      },
      formRules: {
        'balance.min': [
          {
            required: true,
            message: '请输入单次最低赠送金额',
            trigger: 'blur'
          },

        ],
        'balance.charge': [
          {
            required: true,
            message: '请输入手续费',
            trigger: 'blur'
          },
        ],
        'integral.min': [
          {
            required: true,
            message: '请输入单次最低赠送积分',
            trigger: 'blur'
          }
        ],
        'integral.charge': [
          {
            required: true,
            message: '请输入手续费',
            trigger: 'blur'
          }
        ]
      }
    };
  },
  components: {
    Tinymce
  },
  mounted() {
    this.getConfig('assettransfer');
  },
  methods: {
    //获取站点配置数据
    getConfig(type) {
      this.isLoading = true;
      getSiteConfig(type)
        .then(res => {
          this.isLoading = false;
          if (res.msg) {
            this.obj = res.msg;
          }
        })
        .catch(e => {
          this.isLoading = false;
        });
    },
    //保存数据
    saveData() {
      this.isLoading = true;
      // if (this.obj.update_time) {
      //   //更新
      //   editSiteConfig(this.obj)
      //     .then(res => {
      //       this.isLoading = false;
      //       this.getConfig('integralBalance');
      //     })
      //     .catch(e => {
      //       this.isLoading = false;
      //     });
      // } else {
      //新增
      addSiteConfig(this.obj)
        .then(res => {
         this.$refs.ufrom.init()
          this.getConfig('assettransfer');
        })
        .catch(e => {
         this.$refs.ufrom.init()
        });
      // }
    }
  }
};
</script>


